<?php
/**
 * wap 加盟商列表处理
 */
defined('InShopNC') or exit('Access Invalid!');
class franchiserControl extends mobileHomeControl{

	public function __construct() {
        parent::__construct();
    }

	/**
	*获取加盟商列表
	 */
	public function franchiser_listOp(){
		$where  = " where 1=1 ";
		$areaid_1=0;
		$keywords=htmlspecialchars(urldecode($_GET['search_words']));
		//区域ID
		 if(!empty($_GET['area_id']) && intval($_GET['area_id'])>0) {
            $areaid_1 = intval($_GET['area_id']);
			 $where .= " and a.areaid_1 in(".$areaid_1.")";
         }
		else
		{
			$where .= " and a.areaid_1>0 ";
		}

		//分页标识
		if(!empty($_GET['limit']) && intval($_GET['limit']) > 0){
			$start = (int)$_GET['limit'];
		}
		else
		{
			$start = 0;
		}

		if(!empty($keywords) && $keywords!='all')
		{
			$where .= " and a.franchisee_name like '%".$keywords."%' ";
		}

	   $datas = array();

		$num= 10;
		
		$limit = " limit ".$start.",".$num;
		

		
        $franchiser_list = array();
		$fsql = "select a.*,b.file_name from `".DBPRE."franchiser` as a left join `".DBPRE."upload` as b on b.item_id = a.article_id ".$where." order by areaid_1 asc ".$limit;
		$franchiser_list = Db::getALl($fsql);
		
		//分页
		$isMore = false;
		$sql = 'SELECT COUNT(*) as `count` FROM `'.DBPRE.'franchiser` as a '.(isset($where) ? $where : '');

		$franchiser_count = mysqli_fetch_array(Db::query($sql),MYSQLI_ASSOC);
		if($franchiser_count['count']>($start+$num))
		{
			$isMore = true;
		}
		$datas['isMore'] = $isMore;
		$datas['areaid_1'] = $areaid_1;
		$datas['keywords'] = $keywords;
		$datas['limit'] = $start+$num;
        $datas['franchiser_list']=$this->franchiser_list_extend($franchiser_list);
        output_data($datas);
	}
	
	 public function franchiser_list_extend($franchiser_list)
	 {
		 header("Content-type:text/html;charset=utf-8");

		 if(count($franchiser_list))
		 {
			 foreach($franchiser_list as $key=>$value)
			 {

				 $franchiser_list[$key]['article_content'] = preg_replace('/&nbsp;|&ldquo;|&rdquo;|\/r\/n/i','',trim(strip_tags($franchiser_list[$key]['article_content'])));
				//echo($franchiser_list[$key]['article_content']."<br/>");

				 if($franchiser_list[$key]['file_name']=="")
				 {
					 $franchiser_list[$key]['file_name'] = "/wap/images/logo.jpg";
				 }
				 else
				 {
					 $franchiser_list[$key]['file_name'] = "/data/upload/shop/article/".$franchiser_list[$key]['file_name'];
				 }
			 }
			 //exit();
			 return $franchiser_list;
		 }
	 }

	/**
	*获取加盟商详细信息
	 **/
	 public function franchiser_detailOp()
	 {
		 $where = "";
		 if(!empty($_GET['f_id']) && intval($_GET['f_id']) > 0) {
            $f_id = (int)$_GET['f_id'];
			 $where = "where franchisee_id=$f_id";
         }
		 else{exit();}
		$sql = "select f.*,a.article_content,u.file_name from `".DBPRE."franchiser` as f left join `".
			DBPRE."article` as a on a.article_id=f.article_id left join `".DBPRE."upload` as u on u.item_id = f.article_id ".$where;
		 $result = mysqli_fetch_array(Db::query($sql),MYSQLI_ASSOC);


		 if($result)
		 {
			 if($result['file_name']=="")
			 {
				 $result['file_name'] = "/wap/images/logo.jpg";
			 }
			 else
			 {
				 $result['file_name'] = "/data/upload/shop/article/".$result['file_name'];
			 }
			 $datas["franchiser"] = $result;

			 output_data($datas);
		 }

	 }

	/**
	*获取所有加盟商地图坐标信息
	 **/
	public function franchiser_listallOp()
	{
		$franchiser_list = array();
		$fsql = "select * from `".DBPRE."franchiser` ";
		$franchiser_list = Db::getALl($fsql);
		output_data($franchiser_list);

	}
	
}
